#!/usr/bin/env ruby
# A few helpful tips about the Rules file:
#
# * The string given to #compile and #route are matching patterns for
# identifiers--not for paths. Therefore, you can’t match on extension.
#
# * The order of rules is important: for each item, only the first matching
# rule is applied.
#
# * Item identifiers start and end with a slash (e.g. “/about/” for the file
# “content/about.html”). To select all children, grandchildren, … of an
# item, use the pattern “/about/*/”; “/about/*” will also select the parent,
# because “*” matches zero or more characters.
## Generate article categories - category pages
# code copied from http://ithaca.arpinum.org/2012/03/30/adding-categories.html
preprocess do
create_category_pages
end
## Apply Kramdown filter and post layout
# code copied from http://chodounsky.net/2013/04/23/nanoc-project-structure/
# code copied from http://clarkdave.net/2012/02/building-a-static-blog-with-nanoc/
compile 'posts/*' do
filter :kramdown
layout 'post'
end
## Generate image thumbnails
# code adapted from http://nanoc.ws/docs/guides/using-binary-items-effectively/
compile '/assets/*/Frontpage*/', :rep => :thumbnail do
case item[:extension].downcase
when 'jpg', 'gif', 'png', 'bmp'
filter :thumbnailize, :width => 200
end
end
compile '/assets/*/', :rep => :thumbnail do
case item[:extension].downcase
when 'jpg', 'gif', 'png', 'bmp'
filter :thumbnailize, :width => 500
end
end
route '/assets/*/', :rep => :thumbnail do
case item[:extension].downcase
when 'jpg', 'gif', 'png', 'bmp'
item.identifier.chop + ' thumb.' + item[:extension].downcase
end
end
## encapsulate image thumbnails in links to the full size image
#link_to('
', '/assets/post/img.jpg')
# => '
Blog'
## Generate article categories
# code copied from http://ithaca.arpinum.org/2012/03/30/adding-categories.html
# code copied from https://bitbucket.org/telemachus/ithaca/src/9a355af11f3bf35d84d1b1b01423d9542e730e75/Rules?at=master
route '/categories/' do
'/categories.html'
end
route '/categories/*/' do
item.identifier.chop + '.html'
end
## catch-all
compile '*' do
if item[:extension] == 'css'
# don’t filter stylesheets
elsif item.binary?
# don’t filter binary items
else
filter :erb
layout 'default'
end
end
route '*' do
if item[:extension] == 'css'
# Write item with identifier /foo/ to /foo.css
item.identifier.chop + '.css'
elsif item.binary?
# Write item with identifier /foo/ to /foo.ext
item.identifier.chop + '.' + item[:extension]
else
# Write item with identifier /foo/ to /foo/index.html
item.identifier + 'index.html'
end
end
layout '*', :erb